package com.gamutsoft.amb.common.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class for Servlet: CheckCaptchaServlet
 *
 */
public class CheckCaptchaServlet extends javax.servlet.http.HttpServlet
		implements javax.servlet.Servlet {
	static final long serialVersionUID = 1L;
	public static final String SESSION_CAPTCHA = "session.captcha_";

	public CheckCaptchaServlet() {
		super();
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String captcha = request.getParameter("captcha");

		Object obj = request.getSession(false).getAttribute(SESSION_CAPTCHA);
		if (obj != null) {
			String sessionCaptcha = (String) obj;
			if (sessionCaptcha.toLowerCase().equals(captcha.toLowerCase())) {
//				request.getSession().removeAttribute(SESSION_CAPTCHA);
				response.getWriter().write("true");
			} else {
				response.getWriter().write("false");
			}
		} else {
			response.getWriter().write("false");
		}
		response.getWriter().close();
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}